﻿/****************************************************************************
Copyright (c) 2014-2015 凌惊雪 微信:Lingjingxue 邮箱:lingjingxue@sina.com QQ:271487457

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/

using ServerBase.Protocol;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
using UtilLib;
using ServerBase.Config;
using ServerPublic.Manager;
using static ServerBase.Config.Conf;
using ServerPublic.Data;
using ServerGame.Manager;

namespace ServerGame.GameObject
{
    [Desc("MudChar")]
    public class MudChar : MudObj
    {
        public Room Room  { get => (Room)Env; set => Env = value; }


        #region 战斗

        //在战斗
        public bool IsFighting = false;
        //存活
        public bool IsLiving = true;
        //防御
        public bool IsGuarding = false;


        //敌对
        public Dictionary<long, MudChar> DictEnemyNpc = new Dictionary<long, MudChar>();
        public Dictionary<long, MudChar> DictEnemyPlayer = new Dictionary<long, MudChar>();

        #endregion
        
        //种族
        public ERace Race =>
            (Type == EMudObjType.Player
            ? ERace.human
            : (ERace)((this as Npc).Cfg.Race));

        //道行
        public long Exp =>
            (Type == EMudObjType.Player
            ? ((this as Player).DaCommon.Exp)
            : ((this as Npc).Cfg.Exp));


        //技能列表
        public Dictionary<string, int> DictSkills =>
            (Type == EMudObjType.Player
            ? (this as Player).DaCommon.DictSkill
            : (this as Npc).DictSkill);
        //激发列表
        public Dictionary<string, string> DictUsages =>
            (Type == EMudObjType.Player
            ? (this as Player).DaCommon.DictUsage
            : (this as Npc).DictUsage);

        //道具
        public Dictionary<string, Item> DictItems => 
            (Type == EMudObjType.Player
            ? (this as Player).DaCommon.DictItem 
            : (this as Npc).DictItem);
        //装备
        public Dictionary<long, Equip> DictEquips =>
            (Type == EMudObjType.Player
            ? (this as Player).DaCommon.DictEquip
            : (this as Npc).DictEquip);
        //穿戴
        public Dictionary<EEquipType, long> DictWears =>
            (Type == EMudObjType.Player
            ? (this as Player).DaCommon.DictWear
            : (this as Npc).DictWear);


        #region Actions

        //装备兵器类型
        public EWeaponType ActEquipWeaponType = EWeaponType.无;
        //对应兵器技能
        public EUsageType ActEquipUsageType = EUsageType.扑击格斗;
        public string ActEquipWeapon = "";

        public List<ConfigCbtAction> ActList = new List<ConfigCbtAction>();
        public ConfigCbtAction ActUse = new ConfigCbtAction();

        public string ActWeaponName = "";

        public List<string> ActDodgeMsgs = new List<string>();//闪避描述列表
        public List<string> ActParryMsgs = new List<string>();//招架描述列表

        #endregion

        #region Busy

        //忙乱结束ticks
        public long BusyTicksEnd = 0;
        //忙乱豪秒
        public int BusyMs = 0;

        public bool IsBusy => BusyIn();
        public bool BusyIn()
        {
            if (BusyMs <= 0)
            {
                return false;
            }
            if (DateTime.Now.Ticks >= BusyTicksEnd)
            {
                BusyTicksEnd = 0;
                BusyMs = 0;
                return false;
            }
            return true;
        }
        //忙乱开始 毫秒
        public void BusyStart(int ms, bool busynew = true)
        {
            if (ms <= 0)
            {
                return;
            }
            var dtNow = DateTime.Now;
            if (!IsBusy || busynew)
            {
                BusyTicksEnd = dtNow.AddMilliseconds(ms).Ticks;
                BusyMs = ms;
            }
            else
            {
                BusyTicksEnd += ms * TimeSpan.TicksPerMillisecond;
                BusyMs += ms;
            }
        }
        //忙乱结束
        public void BusyStop()
        {
            BusyTicksEnd = 0;
            BusyMs = 0;
        }

        #endregion

        #region virtual

        public virtual string MudRude()
        {
            return "小王八蛋";
        }
        public virtual int this[EProp prop]
        {
            get
            {
                return 0;
            }
            set
            {
            }
        }
        public virtual long this[EPropCbt prop]
        {
            get
            {
                return this.PropCbt(prop);
            }
            set
            {
            }
        }

        #endregion

    }

}
